package pl.jad.database.table.column;

import java.lang.reflect.Field;

abstract public class TableArrayTypes {
	protected int _int;
	protected String _String;
	protected float _float;
	protected boolean _boolean;
	protected byte _byte; 
	protected double _double;
	protected long _long;
	protected char _char; 
	protected short _short;
	
	
	static public Field get(Class<?> Clas) throws SecurityException, NoSuchFieldException {
		Class<?> c;
		
		if (!Clas.isArray()) {
			// this is mainly for array classes
			//throw new IllegalArgumentException("This method works only for arrays");
			c = Clas;
		} else {
			c = Clas.getComponentType();
		}		
		
		// TODO: must have 'c == int.class' ?
		if (c == int.class || c == Integer.class) {
			return TableArrayTypes.class.getDeclaredField("_int");
		} else if (c == "".getClass()) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_String");
		} else if (c == float.class || c == Float.class) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_float");
		} else if (c == boolean.class || c == Boolean.class) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_boolean");
		} else if (c == byte.class || c == Byte.class) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_byte");
		} else if (c == double.class || c == Double.class) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_double");
		} else if (c == long.class || c == Long.class) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_long");
		} else if (c == char.class || c == Character.class) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_char");
		} else if (c == short.class || c == Short.class) {
			// default type
			return TableArrayTypes.class.getDeclaredField("_short");
		} else {
			throw new IllegalArgumentException("Unknown array type: " + c.getName());
		}
	}
}
